package vlcjdemo;


import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class ImageBrowser {
  public static void main(String s[]) {
    AFrame f = new AFrame();
    }
 }

 class AFrame extends Frame implements ActionListener {
   List lbx;
   MyCanvas can;
   String url[] = new String[50];

   public AFrame() {
     setTitle("Image selection, double click to display");
     setLayout(new GridLayout(1,2));
     setSize(800,600);
     lbx = new List();
     can = new MyCanvas();
     add(lbx); add(can);
     initLbx();
     // action on listbox double click
     lbx.addActionListener(this);
     // to close the Frame
     addWindowListener
       (new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
           }
         }
       );
     setVisible(true);
     }

   public void actionPerformed (ActionEvent ae) {
     String theUrl = url[lbx.getSelectedIndex()];
     MediaTracker media = new MediaTracker(this);
     Image image =
        Toolkit.getDefaultToolkit().getImage(theUrl);
     media.addImage(image, 0);
     try {
       media.waitForID(0);
       can.setImage(image);
       }
     catch (Exception e) { e.printStackTrace();}
     }

   public void initLbx() {
     int i = 0;
     try {
       String aLine = "";
       BufferedReader in
         = new BufferedReader(new FileReader("imagelist.txt"));
       while(null != (aLine = in.readLine())) {
          java.util.StringTokenizer st =
             new java.util.StringTokenizer(aLine, "|");
         url[i++] = st.nextToken();
         // lbx.addItem(st.nextToken());
         lbx.add(st.nextToken());
         }
       }
     catch(Exception e) { e.printStackTrace();}
     }
  }

class MyCanvas extends Canvas {
  private Image image;
  public MyCanvas() {
    super();
    }

  public void setImage(Image i) {
    image = i;
    repaint();
    }

  public void paint(Graphics g) {
    if (image != null)
       g.drawImage(image, 0,0, this);
    }
}